package com.example.warehouse.sys.service.impl;

import com.example.warehouse.sys.dao.persist.respository.IRolePermissionRepository;
import com.example.warehouse.sys.pojo.entity.SysRolePermission;
import com.example.warehouse.sys.pojo.param.AddNewRolePermissionParam;
import com.example.warehouse.sys.pojo.vo.RolePermissionVO;
import com.example.warehouse.sys.service.IRolePermissionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Service
@Slf4j
public class RolePermissionServiceImpl implements IRolePermissionService {
    @Autowired
    private IRolePermissionRepository rolePermissionRepository;

    @Override
    public void addNewRolePermissionByList(Long id,List<Long> permissionIdList) {
        rolePermissionRepository.deleteByRoleId(id);
        for(Long permissionId : permissionIdList){
            SysRolePermission sysRolePermission = new SysRolePermission();
            sysRolePermission.setRoleId(id);
            sysRolePermission.setPermissionId(permissionId);
            rolePermissionRepository.insert(sysRolePermission);
        }

    }

    @Override
    public List<Long> selectByRoleId(Long roleId) {
        return rolePermissionRepository.selectList(roleId);
    }
}
